<?php
namespace app\api\controller\v1;
use app\service\PaymentService;
use think\Db;


class User extends Base
{
	public function _initialize()
	{
		parent::_initialize();
		$this->IsLogin(); //验证登录
	}

	/**
	 * 用户信息
	 */
	public function index()
	{
		$user = $this->user;
		
		$coupon_count = 0;
		
		team_get($user['id']);
		team_get2($user['id']);
		
		if (!empty($user)) {
			//处理注册日期
			$user['add_time_time'] = !empty($user['add_time']) ? date('Y-m-d', $user['add_time']) : '';
			$coupon_count = Db::name('coupon_user')->where(['user_id' => $user['id'], 'is_valid' => 1, 'is_expire' => 0, 'is_use' => 0])->count();
		}
		
		
		
		$count=db::name('order')->where(['user_id'=>$user['id'],'status'=>['in','1,2,3,4,5,6']])->count();
        
        // if($count>0){
		  //  $user['upid']=100000;
        // }
        
        $openid=db::name('user_weixin')->where(['user_id'=>$user['id'],'identity_type'=>'user','client_type'=>'h5'])->value('openid');
		
		$user['openid']=$openid;
		
		$result['code'] = 0;
	    $result['msg'] = "请求成功";
	    $result['data'] = [
	    	'user' => $user,
	    	'coupon_count' => $coupon_count
	    ];
	    echo json_encode($result);
	}
	
	
	
	//上级id修改
	public function upid_change(){
	    
		$user = $this->user;
		
		$params = input();
			
		
		$user_techn=db::name('techn')->where('user_id',$user['id'])->find();	
		if(!empty($user_techn)){
		    echo json_encode([
    			'code' => '-1',
    			'msg' => '您已成为技师了',
    		]);
    		exit;
		}
	    
		$uptel=$params['upid'];
		
		$techn=db::name('techn')->where('mobile',$uptel)->find();
		
// 		if(empty($uid)){
// 		    $uid=db::name('techn')->where('mobile',$uptel)->value('user_id');
// 		}
        
        $count=db::name('order')->where(['user_id'=>$user['id'],'status'=>['in','1,2,3,4,5,6']])->count();
        
        if($count>0){
            echo json_encode([
    			'code' => '-1',
    			'msg' => '无权限绑定',
    		]);
    		exit;
        }
        if($techn['upid']==$user['id']){
		    echo json_encode([
    			'code' => '-1',
    			'msg' => '不可绑定的关系',
    		]);
    		exit;
		}
		if(!empty($user['upid'])){
		    echo json_encode([
    			'code' => '-1',
    			'msg' => '已绑定上级',
    		]);
    		exit;
		}
		if(empty($techn)){
		    echo json_encode([
    			'code' => '-1',
    			'msg' => '该技师不存在',
    		]);
    		exit;
		}
		if($user['id']==$techn['user_id']){
		    echo json_encode([
    			'code' => '-1',
    			'msg' => '不可绑定本人',
    		]);
    		exit;
		}
		
		
		db::name('user')->where('id',$user['id'])->update(['upid'=>$techn['user_id'],'bdtime'=>time()]);
		
		team_get($techn['user_id']);
		team_get2($user['id']);
		
		$result['code'] = 0;
		
		$result['msg'] = "修改成功";
        		
		echo json_encode($result);
		
	}
	
	
	/**
	 * 我的客户
	 */
	public function kh_lists()
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		$params = $this->data_post;
		
		$map['khtype']=1;
		$map['balance_type']=3;
		$map['identity_type']='user';
		$map['status']=1;
		$map['identity_id']=$user['id'];

		$orderids=db::name('balance')->where($map)->column('order_id');

		$user_ids=db::name('order')->where('id','in',$orderids)->column('user_id');
		
		$list_data = Db::name('user')
		             ->where(['id'=>['in',$user_ids]])
//		             ->limit(($params['page']-1)*10,10)
		             ->select();
        $list = Db::name('user')->where('top_id',$user['id'])->select();

        foreach($list as $key => $value)
        {
            $list[$key]['images'] = $value['avatar'];
            $user_order = Db::name('order')->where('user_id',$value['id'])->where('status',6)->column('id');
            $money = Db::name('balance')->where('balance_type',3)->where('order_id','in',$user_order)->where('identity_type','user')->where('khtype',1)->where('identity_id',$user['id'])->where('status',1)->sum('yes_money');

            $list[$key]['zhengqian'] = $money;

        }


//		if(!empty($list_data))
//		{
//			//遍历处理
//			foreach($list_data as $key => $value)
//			{
//				$list_data[$key]['images'] = $value['avatar'];
//			}
//			$result['code'] = 0;
//	        $result['msg'] = "请求成功";
//	        $result['data'] = $list_data;
//		}else
//		{
//			$result['code'] = -1;
//	        $result['msg'] = "暂无数据";
//		}


        if(!empty($list))
        {
            $result['code'] = 0;
            $result['msg'] = "请求成功";
            $result['data'] = $list;
        }else
        {
            $result['code'] = -1;
            $result['msg'] = "暂无数据";
        }
		
		echo json_encode($result);
	}
    
    
    
    
    
    /**
	 * 我的团队
	 */
// 	public function team_lists()
// 	{
// 		$result['code'] = -1;
// 		$result['msg'] = "非法请求";
// 		$user = $this->user;
// 		$params = $this->data_post;
		
// 		$map['upid']=$user['id'];
		
// 		$list_data = Db::name('techn')
// 		             ->where($map)
// 		             ->order('bdtime desc')
// 		             ->limit(($params['page']-1)*10,10)
// 		             ->select();
// 		if(!empty($list_data))
// 		{
// 			//遍历处理
// 			foreach($list_data as $key => $value)
// 			{
// 			    $list_data[$key]['bdtime']=date('Y-m-d',$value['bdtime']);
// 				$list_data[$key]['images'] = request()->domain().$value['self_img'];
// 			}
// 			$result['code'] = 0;
// 	        $result['msg'] = "请求成功";
// 	        $result['data'] = $list_data;
// 		}else
// 		{
// 			$result['code'] = -1;
// 	        $result['msg'] = "暂无数据";
// 		}
		
// 		echo json_encode($result);
// 	}
	
	
	
	public function team_lists()
	
	{
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		
// 				if($user['id']==1264){
// 		    $user=db::name('user')->where('id','1551')->find();
// 		}
		
		team_get($user['id']);
		
		$params = $this->data_post;
		
		$map['user_id']=$user['id'];
		
		$list_data = Db::name('user_bd')
		             ->where($map)
		             ->order('id desc')
//		             ->limit(($params['page']-1)*10,10)
		             ->select();
		if(!empty($list_data))
		{
			//遍历处理
			foreach($list_data as $key => $value)
			{
			    $techn=db::name('techn')->where(['user_id'=>$value['bduid'],'upid'=>$user['id']])->find();
			    
			    $users=db::name('user')->where(['id'=>$value['bduid'],'upid'=>$user['id']])->find();
			    
			    $value['bdtime']=!empty($techn)?$techn['bdtime']:$users['bdtime'];
			    $value['self_img']=!empty($techn)?request()->domain().$techn['self_img']:$users['avatar'];
			    $list_data[$key]['nickname']=!empty($techn)?$techn['nickname']:$users['nickname'];
			    $list_data[$key]['mobile']=!empty($techn)?$techn['mobile']:$users['mobile'];
			    $list_data[$key]['bdtime']=date('Y-m-d',$value['bdtime']);
				$list_data[$key]['images'] = $value['self_img'];
			}
			$result['code'] = 0;
	        $result['msg'] = "请求成功";
	        $result['data'] = $list_data;
		}else
		{
			$result['code'] = -1;
	        $result['msg'] = "暂无数据";
		}
		
		echo json_encode($result);
	}



    public function yewu_list()

    {

        $result['code'] = -1;
        $result['msg'] = "非法请求";
        $user = $this->user;

// 				if($user['id']==1264){
// 		    $user=db::name('user')->where('id','1551')->find();
// 		}

        team_get($user['id']);

        $params = $this->data_post;

        $map['user_id']=$user['id'];

        $list_data = Db::name('user_bd')
            ->where($map)
            ->order('id desc')
//            ->limit(($params['page']-1)*10,10)
            ->select();

        $list_data = Db::name('user')->where('g_uid',$user['id'])->select();
        if(!empty($list_data))
        {
            //遍历处理
            foreach($list_data as $key => $value)
            {

                $list_data[$key]['nickname']=$value['nickname'];
                $list_data[$key]['mobile']=$value['mobile'];
                $list_data[$key]['bdtime']=date('Y-m-d',$value['bdtime']);
                $list_data[$key]['images'] = $value['avatar'];
                $orders = Db::name('balance')->where('identity_type','user')->where('balance_type',3)->where('identity_id',$value['id'])->column('order_id');
                $list_data[$key]['yj_num'] = Db::name('balance')->where('order_id','in',$orders)->where('balance_type',7)->where('status',1)->sum('yes_money');

            }
            $result['code'] = 0;
            $result['msg'] = "请求成功";
            $result['data'] = $list_data;
        }else
        {
            $result['code'] = -1;
            $result['msg'] = "暂无数据";
        }

        echo json_encode($result);
    }


    public function ywj_lists()
    {
        $result['code'] = -1;
        $result['msg'] = "非法请求";
        $user = $this->user;
        $params = $this->data_post;

// 		if($user['id']==1264){
// 		    $user=db::name('user')->where('id','5')->find();
// 		}

        $map['balance_type']=['in','3,4,5,6'];
        $map['identity_type']='user';
        $map['status']=1;
        $map['identity_id']=$user['id'];
        $map['khtype']=$params['khtype'];

        if($params['khtype']==1){//客户
            $yongjin=db::name('user')->where('id',$user['id'])->value('yongjin');
        }elseif($params['khtype'] == 2){
            $yongjin=db::name('user')->where('id',$user['id'])->value('yongjin2');
        }else{
            $yongjin=db::name('user')->where('id',$user['id'])->value('yewujin');

        }

        $list_data = Db::name('balance')
            ->where($map)
            ->order('id desc')
            ->limit(($params['page']-1)*10,10)
            ->select();

        if ($params['khtype'] == 3){
            $map['balance_type']=['in','7,8,9'];
            $map['identity_type']='user';
            $map['status']=1;
            $map['identity_id']=$user['id'];
            $map['khtype']=$params['khtype'];

            $list_data = Db::name('balance')
                ->where($map)
                ->order('id desc')
                ->limit(($params['page']-1)*10,10)
                ->select();
        }

        $result_list=[];

        if ($params['khtype'] != 3){
            if(!empty($list_data))
            {
                //遍历处理
                foreach($list_data as $key => $value)
                {
                    $result_list[$key]['order_id']=0;
                    if($value['balance_type']==5){
                        $result_list[$key]['title']='申请提现';
                        $result_list[$key]['msg']='';
                        $result_list[$key]['price']='-'.$value['yes_money'];
                    }elseif($value['balance_type']==6){
                        $result_list[$key]['title']='佣金提现驳回';
                        $result_list[$key]['msg']='驳回理由：'.$value['msg'];
                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }else{
                        $result_list[$key]['order_id']=$value['order_id'];
                        $order=db::name('order')->where('id',$value['order_id'])->find();
                        $titles=db::name('order_detail')->where('order_id',$value['order_id'])->column('title');
                        $titleall=implode(',',$titles);

                        $result_list[$key]['title']=$titleall.'(￥'.$value['price'].')';
                        if($value['balance_type']==3){
                            $result_list[$key]['msg']='昵称：'.db::name('user')->where('id',$order['user_id'])->value('nickname');
                        }else{
                            $result_list[$key]['msg']='昵称：'.db::name('techn')->where('user_id',$order['user_id'])->value('nickname');
                        }

                        $result_list[$key]['msg'].='            下单时间：'.date('Y-m-d H:i:s',$value['add_time']);

                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }
                }
                $result['code'] = 0;
                $result['msg'] = "请求成功";
                $result['data'] = $result_list;
                $result['yongjin'] = $yongjin;
            }else
            {
                $result['code'] = -1;
                $result['msg'] = "暂无数据.";
            }
        }else{
            if(!empty($list_data))
            {
                //遍历处理
                foreach($list_data as $key => $value)
                {
                    $result_list[$key]['order_id']=0;
                    if($value['balance_type']==8){
                        $result_list[$key]['title']='业务佣金提现';
                        $result_list[$key]['msg']='';
                        $result_list[$key]['price']='-'.$value['yes_money'];
                    }elseif($value['balance_type']==9){
                        $result_list[$key]['title']='业务佣金提现驳回';
                        $result_list[$key]['msg']='驳回理由：'.$value['msg'];
                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }else{
                        $result_list[$key]['order_id']=$value['order_id'];
                        $order=db::name('order')->where('id',$value['order_id'])->find();
                        $titles=db::name('order_detail')->where('order_id',$value['order_id'])->column('title');
                        $titleall=implode(',',$titles);

                        $result_list[$key]['title']=$titleall.'(￥'.$value['price'].')';
                        if($value['balance_type']==7){
                            $result_list[$key]['msg']='昵称：'.db::name('user')->where('id',$order['user_id'])->value('nickname');
                        }else{
                            $result_list[$key]['msg']='昵称：'.db::name('techn')->where('user_id',$order['user_id'])->value('nickname');
                        }

                        $result_list[$key]['msg'].='            下单时间：'.date('Y-m-d H:i:s',$value['add_time']);

                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }
                }
                $result['code'] = 0;
                $result['msg'] = "请求成功";
                $result['data'] = $result_list;
                $result['yongjin'] = $yongjin;
            }else
            {
                $result['code'] = -1;
                $result['msg'] = "暂无数据.";
            }
        }


        echo json_encode($result);
    }


    /**
	 * 我的佣金
	 */
	public function yj_lists()
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		$params = $this->data_post;
		
// 		if($user['id']==1264){
// 		    $user=db::name('user')->where('id','5')->find();
// 		}
		
		$map['balance_type']=['in','3,4,5,6'];
		$map['identity_type']='user';
		$map['status']=1;
		$map['identity_id']=$user['id'];
		$map['khtype']=$params['khtype'];
		
		if($params['khtype']==1){//客户
		    $yongjin=db::name('user')->where('id',$user['id'])->value('yongjin');
		}elseif($params['khtype'] == 2){
		    $yongjin=db::name('user')->where('id',$user['id'])->value('yongjin2');
		}else{
            $yongjin=db::name('user')->where('id',$user['id'])->value('yewujin');

        }
		
		$list_data = Db::name('balance')
		             ->where($map)
		             ->order('id desc')
		             ->limit(($params['page']-1)*10,10)
		             ->select();

        if ($params['khtype'] == 3){
            $map['balance_type']=['in','7,8,9'];
            $map['identity_type']='user';
            $map['status']=1;
            $map['identity_id']=$user['id'];
            $map['khtype']=$params['khtype'];

            $list_data = Db::name('balance')
                ->where($map)
                ->order('id desc')
                ->limit(($params['page']-1)*10,10)
                ->select();
        }

		$result_list=[];

        if ($params['khtype'] != 3){
            if(!empty($list_data))
            {
                //遍历处理
                foreach($list_data as $key => $value)
                {
                    $result_list[$key]['order_id']=0;
                    if($value['balance_type']==5){
                        $result_list[$key]['title']='申请提现';
                        $result_list[$key]['msg']='';
                        $result_list[$key]['price']='-'.$value['yes_money'];
                    }elseif($value['balance_type']==6){
                        $result_list[$key]['title']='佣金提现驳回';
                        $result_list[$key]['msg']='驳回理由：'.$value['msg'];
                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }else{
                        $result_list[$key]['order_id']=$value['order_id'];
                        $order=db::name('order')->where('id',$value['order_id'])->find();
                        $titles=db::name('order_detail')->where('order_id',$value['order_id'])->column('title');
                        $titleall=implode(',',$titles);

                        $result_list[$key]['title']=$titleall.'(￥'.$value['price'].')';
                        if($value['balance_type']==3){
                            $result_list[$key]['msg']='昵称：'.db::name('user')->where('id',$order['user_id'])->value('nickname');
                        }else{
                            $result_list[$key]['msg']='昵称：'.db::name('techn')->where('user_id',$order['user_id'])->value('nickname');
                        }

                        $result_list[$key]['msg'].='            下单时间：'.date('Y-m-d H:i:s',$value['add_time']);

                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }
                }
                $result['code'] = 0;
                $result['msg'] = "请求成功";
                $result['data'] = $result_list;
                $result['yongjin'] = $yongjin;
            }else
            {
                $result['code'] = -1;
                $result['msg'] = "暂无数据.";
            }
        }else{
            if(!empty($list_data))
            {
                //遍历处理
                foreach($list_data as $key => $value)
                {
                    $result_list[$key]['order_id']=0;
                    if($value['balance_type']==8){
                        $result_list[$key]['title']='业务佣金提现';
                        $result_list[$key]['msg']='';
                        $result_list[$key]['price']='-'.$value['yes_money'];
                    }elseif($value['balance_type']==9){
                        $result_list[$key]['title']='业务佣金提现驳回';
                        $result_list[$key]['msg']='驳回理由：'.$value['msg'];
                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }else{
                        $result_list[$key]['order_id']=$value['order_id'];
                        $order=db::name('order')->where('id',$value['order_id'])->find();
                        $titles=db::name('order_detail')->where('order_id',$value['order_id'])->column('title');
                        $titleall=implode(',',$titles);

                        $result_list[$key]['title']=$titleall.'(￥'.$value['price'].')';
                        if($value['balance_type']==7){
                            $result_list[$key]['msg']='昵称：'.db::name('user')->where('id',$order['user_id'])->value('nickname');
                        }else{
                            $result_list[$key]['msg']='昵称：'.db::name('techn')->where('user_id',$order['user_id'])->value('nickname');
                        }

                        $result_list[$key]['msg'].='            下单时间：'.date('Y-m-d H:i:s',$value['add_time']);

                        $result_list[$key]['price']='+'.$value['yes_money'];
                    }
                }
                $result['code'] = 0;
                $result['msg'] = "请求成功";
                $result['data'] = $result_list;
                $result['yongjin'] = $yongjin;
            }else
            {
                $result['code'] = -1;
                $result['msg'] = "暂无数据.";
            }
        }

		
		echo json_encode($result);
	}
	
	
	
	
	public function tixian(){
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
        $user['yewujin'] = Db::name('user')->where('id',$user['id'])->value('yewujin');
		$params = $this->data_post;
		$txtype=$params['txtype'];//1是从团队 2是客户 3是业务员
		
		if($txtype==1){
		    $yongjin=$user['yongjin2'];
		    $khtype=2;
		}elseif($txtype == 2){
		    $yongjin=$user['yongjin'];
		    $khtype=1;
		}else{
            $yongjin=$user['yewujin'];
            $khtype=3;
        }
		if($yongjin<=0){
		    $result['code'] = -1;
			$result['msg'] = "佣金提现金额不足";
		    echo json_encode($result);
		    exit;
		}
		
		if($yongjin<$params['price']){
		    $result['code'] = -1;
			$result['msg'] = "佣金提现金额不足";
		    echo json_encode($result);
		    exit;
		}
		
		//启动事务
			Db::startTrans();
			try{
			    if($txtype==1){
			        db::name('user')->where('id',$user['id'])->setDec('yongjin2',$params['price']);
        		}elseif($txtype == 2){
			        db::name('user')->where('id',$user['id'])->setDec('yongjin',$params['price']);
        		}else{
                    db::name('user')->where('id',$user['id'])->setDec('yewujin',$params['price']);

                }
			    
			    $id=db::name('yj_tixian')->insertGetId([
        		    'user_id'=>$user['id'],
        		    'mobile'=>$params['mobile'],
        		    'real_name'=>$params['real_name'],
        		    'type'=>$params['type'],
        		    'bankname'=>$params['bankname'],
        		    'banknum'=>$params['banknum'],
        		    'price'=>$params['price'],
        		    'zfnum'=>$params['zfnum'],
        		    'reason'=>'业务员提现',
        		    'add_time'=>time(),
        		    'khtype'=>$khtype
        		    ]);
			    db::name('balance')->insert([
        		    'identity_id'=>$user['id'],
        		    'balance_type'=>8,
        		    'order_id'=>$id,
        		    'identity_type'=>'user',
        		    'divide_into'=>0,
        		    'price'=>$params['price'],
        		    'no_money'=>$params['price'],
        		    'yes_money'=>$params['price'],
        		    'msg'=>'业务员提现',
        		    'status'=>1,
        		    'add_time'=>time(),
        		    'upd_time'=>time(),
        		    'khtype'=>$khtype
        		    
        		    ]);

				//提交事务
				Db::commit();
				$result['code'] = 0;
				$result['msg'] = "操作成功";
				
			} catch (\Exception $e) {
				//回滚事务
				Db::rollback();
				$result['code'] = -1;
				$result['msg'] = "操作失败";
			}

		echo json_encode($result);
		    exit;
		
	}
	
	public function rechange_list(){
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		
		$list=db::name('balance_rechange')->where('is_delete_time',0)->select();

		$result['code'] = 0;
		$result['msg'] = "操作成功";
		$result['data']=$list;
		echo json_encode($result);
		    exit;
		
		
		
	}
	
	
	public function rechange(){
	    
	    
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		$params = $this->data_post;
// 		if($user['id']!=1264){
// 		    echo json_encode(['code' => -1, 'msg' => '关闭中']);
// 			exit();
// 		}
		
		$info=db::name('balance_rechange')->where('id',$params['id'])->find();
        if (empty($info)){
            $info['price'] = $params['rechange_my'];
            $info['zprice'] = 0;
            $info['fprice'] = $params['rechange_my'];
        }
		
		$data['add_time']=time();
		$data['user_id']=$user['id'];
		$data['price']=$info['price'];
		$data['zprice']=$info['zprice'];
		$data['fprice']=$info['fprice'];
		$data['uptel']=$params['mobile'];
        //如果有技师手机号,添加技师积分
        if (!empty($params['mobile'])){
            $techn_info = Db::name('techn')->where('mobile',$params['mobile'])->find();
            if (!empty($techn_info)){
                $jf = Db::name('techn_last')->where('techn_id',$techn_info['id'])->find();
                $updata = ['temp_integral'=>$info['fprice']+$jf['total_integral']];
                Db::name('techn_last')->where('techn_id',$techn_info['id'])->update($updata);
            }
        }
		$data['order_no']=date('YmdHis').GetRandomStr(6,'int');;
		
		$orderid=db::name('user_rechange')->insertGetId($data);
		
		
		$result['code'] = 0;
		$result['msg'] = "操作成功";
		$result['data'] = [
			'order_id' => $orderid
		];
		echo json_encode($result);
	    exit;
	}
	
	
	
	public function pay()
	{
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		$params['user'] = $this->user;
		
		
        //查询订单信息
        $order_info = Db::name('user_rechange')->where(['id' => $params['order_id']])->find();
        
        
        // 支付方式
        $payment_array = PaymentService::$payment_array;
        $payment = $payment_array[1];
        if(empty($payment))
        {
        	echo json_encode(['code' => -1, 'msg' => '支付方式有误']);
			exit();
        }
        
        //支付参数
        $pay_data = [
        	'user' => $params['user'],
        	'order_id' => $order_info['id'],
        	'order_no' => $order_info['order_no'],
        	'name' => '订单支付',
        	'total_price' => $order_info['price'],
        	'client_type' => 'h5',
        	'notify_url' => request()->domain().'/api/v1/ordernotify/rechange',
        	'call_back_url' => request()->domain().'/h5/pages/order/order',
        	'redirect_url' => '',
        	'site_name' => '摩小妹',
        	'ajax_url' => '',
        ];
        
        
        
        // 发起支付
        $pay_name = 'payment\Weixin';
        $ret = (new $pay_name($payment['config']['user']))->Pay($pay_data);
        if(isset($ret['code']) && $ret['code'] == 0)
        {
        	$result = $ret;
        }else
        {
        	$result['code'] = -100;
        	$result['msg'] = empty($ret['msg']) ? '支付接口异常' : $ret['msg'];
        }
        echo json_encode($result);
	}
	
	//充值记录
	public function user_balance_jl(){
	    $result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		$user = $this->user;
		
		
		
		$data['list'] = Db::name('money_log')->where(['identity_type' => 'user','identity_id'=>$user['id'],'money_type'=>0])->order('id desc')->limit(($params['page']-1)*10,10)->select();
		foreach ($data['list'] as $k=>$v){
		    $data['list'][$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
		    if($v['operation_type']==1){
		        $data['list'][$k]['price']='+'.$v['operation_money'];
		    }else{
		        $data['list'][$k]['price']='-'.$v['operation_money'];
		    }
		    if($v['business_type']==1){
		        $data['list'][$k]['title']='消费';
		    }elseif($v['business_type']==2){
		        $data['list'][$k]['title']='退款';
		    }elseif($v['business_type']==3){
		        $data['list'][$k]['title']='充值';
		    }elseif($v['business_type']==6){
		        $data['list'][$k]['title']='提现';
		    }else{
		        $data['list'][$k]['title']='';
		    }
		    
		}
		
		$data['money']=$user['money'];
		
        $result['code'] = 0;
        $result['msg'] = "请求成功";
        $result['data'] = $data;
        
		echo json_encode($result);
        
	}
	
	//用户反馈
	public function order_fk(){
	    
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$user = $this->user;
		$params = $this->data_post;
        $p = ['接私单（私自接受现金，转账等）','向客户所有消费','涉及黄赌毒','言行举止恶劣'];
        $title = '';
		foreach ($params['p'] as $ka => $va){
            if ($va == 'y'){
                $title .= $p[$ka].';';
            }
        }
		$data['add_time']=time();
		$data['user_id']=$user['id'];
		$data['img']=$params['img'];
		$data['reason']=$params['reason'];
		$data['techn_name']=$params['techn'];
		$data['tousu']=$title;

		db::name('user_fk')->insert($data);
		
		$result['code'] = 0;
		$result['msg'] = "操作成功";
		echo json_encode($result);
		    exit;
				
	}

    public function fk_list(){
        $user = $this->user;
        $list = Db::name('user_fk')->where('user_id',$user['id'])->order('id desc')->select();
        if (!empty($list)){
            foreach ($list as $key => $value){
                $list[$key]['add_time_time'] = date('Y-m-d H:i:s',$value['add_time']);
                $list[$key]['techn_name'] = $value['techn_name'] == '点击选择' ? '无' : $value['techn_name'];
            }
            $result['code'] = 0;
            $result['msg'] = "操作成功";
            $result['data'] = $list;
            echo json_encode($result);
            exit;
        }

    }
    public function techn_list(){
        $user_id = $this->user['id'];
        $techn_id = Db::name('order')->where('user_id',$user_id)->group('techn_id')->column('techn_id');
        $list = [];
        $in = implode(',',$techn_id);
        $list = Db::name('techn')->where('id','in',$in)->field('id,nickname,work_img')->select();
        foreach ($list as $key => $value){
            $list[$key]['work_img']=!empty($value['work_img'])?request()->domain().$value['work_img']:'';
        }

//        $list = Db::name('techn')->where('id','in',$in)->column('nickname');

        if (!empty($list)){
            $return['code'] = 0;
            $return['msg'] = '成功';
            $return['data'] = $list;
        }else{
            $return['code'] = -1;
            $return['msg'] = '失败';
        }
        echo json_encode($return);
    }
	
}